
#include <iostream>
#include <cstdlib>
#include <stdint.h>
#include <windows.h>
#include "FlameMath.h"

#include "StopWatch.h"

using namespace std;
using namespace FlameEngineMath;
using namespace FlameEngine;

void PrintFloat4(const Float4& vec)
{
	cout<<"("<<vec.x<<","<<vec.y<<","<<vec.z<<","<<vec.w<<")\n";
}

void PrintMatrix4x4(const Float4x4& mat)
{
	cout<<"("<<mat._11<<","<<mat._12<<","<<mat._13<<","<<mat._14<<")\n"
		<<"("<<mat._21<<","<<mat._22<<","<<mat._23<<","<<mat._24<<")\n"
		<<"("<<mat._31<<","<<mat._32<<","<<mat._33<<","<<mat._34<<")\n"
		<<"("<<mat._41<<","<<mat._42<<","<<mat._43<<","<<mat._44<<")\n";
}

__declspec(noinline) void RunMathLibTest(int seed)
{
	//test inline
	srand(seed);
	Float4 f0(rand()%100,rand()%100,rand()%100,rand()%100);
	Float4 f1(rand()%100 ,rand()%100,rand()%100,rand()%100);
	MathHelper::Multiply(f1,0.00001f,f1);
	PrintFloat4(f0);
	PrintFloat4(f1);
	Float4 f3 = f0+f1;

	PrintFloat4(f3);

	Vector4 v0 = LoadFloat4(&f3);
	Vector4 v1 = LoadFloat4(&f1);
	Vector4 v3 = v0 + v1;
	StoreFloat4(&f3,v3);
	PrintFloat4(f3);

	Matrix mat = MatrixRotationRollPitchYawFromVector(v3);
	Float4x4 fMat;
	StoreFloat4x4(&fMat,mat);
	PrintMatrix4x4(fMat);

	StopWatch stopWatch;
	uint32_t runs = 1000000000;
	f3.MakeZero();

	/*********************sse performance test***********************/
	std::cout<<"==========================\n";
	stopWatch.Start();
	for(int i=0;i<runs;i++)
	{
		f3 += f1;
	}
	stopWatch.Stop();
	PrintFloat4(f3);
	std::cout<<"time:"<<stopWatch.GetElapsedTime()<<"\n";

	stopWatch.Reset();
	v3 = VectorZero();

	stopWatch.Start();
	for(int i=0;i<runs;i++)
	{
		v3 += v1;
	}
	stopWatch.Stop();
	StoreFloat4(&f3,v3);
	PrintFloat4(f3);
	std::cout<<"time:"<<stopWatch.GetElapsedTime()<<"\n";
	
	/*Simpe add operation SIMD version is 3 times faster

	/////////////////////////////////////////////////////////////////
	*/
}

